#include "Body.h"
#include "System\GameObject.h"

mtBEGIN(Body)
	mtBASE(ECS::Component);
mtEND

Body::Body()
{

}

Body::~Body()
{

}

void Body::onStart()
{
    // definition of body
    b2BodyDef def;
    def.bullet = true;
    def.active = true;
    def.type = b2_dynamicBody;
    def.userData = this;
    def.position = b2Vec2(0.0f, 0.0f);

    // definition of fixtures
    b2FixtureDef fd;
    fd.density = 1.0f;
    fd.isSensor = false;
    b2CircleShape shape;
    shape.m_radius = 0.25f;
    fd.shape = &shape;

    _body = World::Instance()->getWorld()->CreateBody(&def);
    _body->CreateFixture(&fd);
}

b2Body* Body::getBody() const
{
    return _body;
}

void Body::setPosition( const Vector& position )
{
    _body->SetTransform(b2Vec2(position.x, position.y), _body->GetAngle());
}

void Body::setBodyType( b2BodyType type )
{
    _body->SetType(type);
}

b2BodyType Body::getBodyType() const
{
    return _body->GetType();
}
